package com.project.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.EmployeeBean;
import com.project.mapper.IDeptMapper;
import com.project.mapper.IEmployeeMapper;
import com.project.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class EmployeeServiceImpl implements IEmployeeService {
    @Autowired
    private IEmployeeMapper emMapper;
    @Autowired
    private IDeptMapper deptMapper;

    @Override
    public void add(EmployeeBean em) {
        emMapper.insert(em);
    }

    @Override
    public List<EmployeeBean> findAll() {
        return emMapper.findAll();
    }

    @Override
    public EmployeeBean findById(Integer id) {
        EmployeeBean em = emMapper.selectById(id);
        em.setDept(deptMapper.selectById(em.getDeptId()));

        return em;
    }

    @Override
    public IPage<EmployeeBean> cutByItem(Integer pageNO, String emName, String deptName) {
        return emMapper.cutByItem(new Page(pageNO,3),emName,deptName);
    }
}
